package com.chat.controller;

import com.chat.entry.dto.friend.AddFriendDTO;
import com.chat.result.Result;
import com.chat.service.IFriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 好友表 前端控制器
 * </p>
 *
 * @author
 * @since 2025-08-21
 */
@Slf4j
@Api(tags = "好友接口管理")
@RestController
@RequestMapping("/api/friend")
@RequiredArgsConstructor
public class FriendController {

    private final IFriendService friendService;

    @ApiOperation(value = "搜索好友", notes = "根据用户名搜索好友")
    @GetMapping("/search")
    public Result searchFriend(
            @ApiParam(value = "当前用户的ID", required = true) @RequestParam Integer userId,
            @ApiParam(value = "要搜索的用户名", required = true) @RequestParam String username
    ) {
        return friendService.searchFriend(userId, username);
    }

    @ApiOperation(value = "发送好友申请", notes = "向指定用户发送好友请求")
    @PostMapping("/add")
    public Result addFriend(
            @ApiParam(value = "好友申请信息", required = true) @RequestBody AddFriendDTO addFriendDTO
    ) {
        return friendService.sendAddFriend(addFriendDTO);
    }

    @ApiOperation(value = "同意好友申请", notes = "同意对方的好友请求")
    @PostMapping("/agree")
    public Result agreeFriend(
            @ApiParam(value = "好友申请信息", required = true) @RequestBody AddFriendDTO addFriendDTO
    ) {
        return friendService.agreeFriend(addFriendDTO);
    }

    @ApiOperation(value = "拒绝好友申请", notes = "拒绝对方的好友请求")
    @PostMapping("/refuse")
    public Result refuseFriend(
            @ApiParam(value = "好友申请信息", required = true) @RequestBody AddFriendDTO addFriendDTO
    ) {
        return friendService.refuseFriend(addFriendDTO);
    }

    @ApiOperation(value = "查询好友申请", notes = "获取当前用户收到的所有好友申请")
    @GetMapping("/applications")
    public Result queryFriendApplication(
            @ApiParam(value = "当前用户的ID", required = true) @RequestParam Integer userId
    ) {
        return friendService.queryFriendApplication(userId);
    }

    @ApiOperation(value = "查询好友列表", notes = "获取当前用户的所有好友")
    @GetMapping("/list")
    public Result queryFriend(
            @ApiParam(value = "当前用户的ID", required = true) @RequestParam Integer userId
    ) {
        return friendService.queryFriend(userId);
    }
}
